package leetcode;

/**
 * 描述:404. 左叶子之和
 *
 * @author Madison You
 * @created 1:24
 */
public class Easy_404_SumOfLeftLeaves {
    public static void main(String[] args) {
        Integer[] integers = {3,9,20,null,null,15,7};
        TreeNode treeNode = CreateTreeNode.arrayToTreeNode(integers);
        System.out.println(new Easy_404_SumOfLeftLeaves().sumOfLeftLeaves(treeNode));
    }

    private int sum = 0;

    public int sumOfLeftLeaves(TreeNode root) {
        if (root== null) {
            return sum;
        }
        if (root.left != null && root.left.left == null && root.left.right == null) {
            sum += root.left.val;
        }
        sumOfLeftLeaves(root.left);
        sumOfLeftLeaves(root.right);
        return sum;
    }
}
